You said:
role: a senior developer proficient in Python
task: Your task is to review the code presented to you. This code will be run in a production environment so you should apply full code standards in your review. Present your feedback as a list and give the user a set of task to complete in order to bring the code up to standard. If you think the code is already up to standard, you can say that the code is good. You should be stern but fair in your review. Some rules that apply:
code should be documented (in numpy style).
code should be DRY.
code should be readable.
code should be efficient.
finally, after completing your review. Give a verdict: either accept or reject the code.
question: Please review the following code:
"""
import turtle
win = turtle.Screen()
win.title("Pong by Your Name")
win.bgcolor("black")
win.setup(width=1000, height=500)
left_paddle = turtle.Turtle()
left_paddle.speed(0)
left_paddle.shape("square")
left_paddle.color("white")
left_paddle.shapesize(stretch_wid=6, stretch_len=1)
left_paddle.penup()
left_paddle.goto(-450, 0)
right_paddle = turtle.Turtle()
right_paddle.speed(0)
right_paddle.shape("square")
right_paddle.color("white")
right_paddle.shapesize(stretch_wid=6, stretch_len=1)
right_paddle.penup()
right_paddle.goto(450, 0)
ball = turtle.Turtle()
ball.speed(40)
ball.shape("square")
ball.color("white")
ball.penup()
ball.goto(0, 0)
ball.dx = 6
ball.dy = -2
score_left = 0
score_right = 0
score_display = turtle.Turtle()
score_display.speed(0)
score_display.color("white")
score_display.penup()
score_display.hideturtle()
score_display.goto(0, 210)
score_display.write("Left: 0 Right: 0", align="center", font=("Courier", 24, "normal"))
def left_paddle_up():
y = left_paddle.ycor()
if y < 250:
left_paddle.sety(y + 20)
def left_paddle_down():
y = left_paddle.ycor()
if y > -240:
left_paddle.sety(y - 20)
def right_paddle_up():
y = right_paddle.ycor()
if y < 250:
right_paddle.sety(y + 20)
def right_paddle_down():
y = right_paddle.ycor()
if y > -240:
right_paddle.sety(y - 20)
win.listen()
win.onkeypress(left_paddle_up, "w")
win.onkeypress(left_paddle_down, "s")
win.onkeypress(right_paddle_up, "Up")
win.onkeypress(right_paddle_down, "Down")
while score_left < 10 and score_right < 10:
win.update()
ball.setx(ball.xcor() + ball.dx)
ball.sety(ball.ycor() + ball.dy)
if ball.ycor() > 240:
ball.sety(240)
ball.dy *= -1
if ball.ycor() < -240:
ball.sety(-240)
ball.dy *= -1
if ball.xcor() > 490:
ball.goto(0, 0)
ball.dx *= -1
score_left += 1
score_display.clear()
score_display.write("Left: {} Right: {}".format(score_left, score_right), align="center", font=("Courier", 24, "normal"))
if ball.xcor() < -490:
ball.goto(0, 0)
ball.dx *= -1
score_right += 1
score_display.clear()
score_display.write("Left: {} Right: {}".format(score_left, score_right), align="center", font=("Courier", 24, "normal"))
if (ball.xcor() > 430 and ball.xcor() < 440) and (ball.ycor() < right_paddle.ycor() + 50 and ball.ycor() > right_paddle.ycor() - 50):
ball.setx(430)
ball.dx *= -1
if (ball.xcor() < -430 and ball.xcor() > -440) and (ball.ycor() < left_paddle.ycor() + 50 and ball.ycor() > left_paddle.ycor() - 50):
ball.setx(-430)
ball.dx *= -1
score_display.goto(0, 0)
score_display.write("Game Over", align="center", font=("Courier", 32, "normal"))
turtle.done()
"""